package org.zoomdev.zoom.dao.adapters.statement;

import org.zoomdev.zoom.common.caster.ValueCaster;
import org.zoomdev.zoom.dao.adapters.StatementAdapter;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 比如Map到clob
 */
public class CasterProxyStatementAdapter implements StatementAdapter {
    private final ValueCaster valueCaster;
    private final StatementAdapter statementAdapter;

    public CasterProxyStatementAdapter(ValueCaster valueCaster, StatementAdapter statementAdapter) {
        this.valueCaster = valueCaster;
        this.statementAdapter = statementAdapter;
    }

    @Override
    public void adapt(PreparedStatement statement, int index, Object value) throws SQLException {
        value = valueCaster.to(value);
        statementAdapter.adapt(statement, index, value);
    }
}
